
const Service = require('egg').Service;
class GoodsfactoryService extends Service {
  /**
   *
   *
   * @param {*} list
   * @param {*} type  1生产组装分类
   * @memberof GoodsfactoryService
   */
  async production(list, type) {
    var servedata = list.map(val => {
      if (val.platform == 1) {
        return val
      }
    })
    var webdata = list.map(val => {
      if (val.platform == 2) {
        return val
      }
    })
    this.ctx.service.result.find({
      servedata: detection(servedata),
      webdata: detection(webdata),
    })
  }

}
module.exports = GoodsfactoryService;


function detection(array) {
  var list = []
  array.forEach(element => {
    if (element && element.parentId == 0) {
      list.push({
        value: element.id,
        label: element.catName,
        children: []
      })
    }
  });
  list.forEach(val => {
    array.forEach(element => {
      if (element && element.parentId == val.value) {
        val.children.push({
          value: element.id,
          label: element.catName,
        })
      }
    });

  })
  return list
}